import React, {Component} from 'react';
import PubSub from 'pubsub-js'
export default class Search extends Component {

    handleClick = () => {
        // 获取输入框的值
        const searchName = this.searchInput.value.trim();

        if (searchName) {
            // 搜索
            // 发布消息(search)
            PubSub.publish("search", searchName);
        }

    }

    render() {
        return (
            <section className="jumbotron">
                <h3 className="jumbotron-heading">Search Github Users</h3>
                <div>
                    <input type="text" placeholder="enter the name you search" ref={input => {
                        this.searchInput = input
                    }}/>
                    <button onClick={this.handleClick}>Search</button>
                </div>
            </section>
        )
    }
};